import 'package:http_server/http_server.dart';

import '../manager/FileManager.dart';
import '../manager/ScoreManager.dart';
import 'dart:io';
import '../utils/LxServer.dart';
import 'tools.dart';

//Get方法
Future<void> HandleGetDefault(HttpRequest req, DeferFuncs deferFuncs) async {
  safeResponse('hello world!', req);
}

//Post方法
Future<void> HandlePostDefault(HttpRequest req, DeferFuncs deferFuncs) async {
  var body = await HttpBodyHandler.processRequest(req);
  safeResponse(body.body, req);
}

//数据库Demo
Future<void> HandleGetScores(HttpRequest req, DeferFuncs deferFuncs) async {
  var manager = await ScoreManager.GetConn();
  deferFuncs.add(manager.db.close);
  var scores = await manager.getGetUpDays();
  safeResponse(scores, req);
}

//返回文件Demo
Future<void> HandleHtml(HttpRequest req, DeferFuncs deferFuncs) async {
  var index_path = r'/../webApp/index.html';
  FileManager.sendFile(index_path, req);
  return;
}
